package com.dotflat.check.repository;

import com.dotflat.check.domain.CheckCard;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Repository
public interface CheckCardRepository extends JpaRepository<CheckCard, String>, JpaSpecificationExecutor<CheckCard> {

    @Transactional
    @Modifying
    @Query(value=" delete from c_check_card where cardNo = ?1 ",nativeQuery = true)
    int deleteCardNo(String cardNo);

    @Query(value=" select * from c_check_card where cardNo = ?1 ",nativeQuery = true)
    CheckCard findByCardNo(String cardNo);

    @Query(value=" select * from c_check_card where cardCode = ?1 ",nativeQuery = true)
    CheckCard findByCardCode(String cardCode);

    Page<CheckCard> findByAreaId(String areaId, Pageable pageable);

    List<CheckCard> findByTypeAndUserIdIn(int type,String[] userIds);

    List<CheckCard> findByTypeAndAreaId(int type,String areaId);
}
